<template>
     <el-button type="primary" plain @click="dialogFormVisible = true">
    添加类别
  </el-button>
      <el-button  >批量删除</el-button>
      <el-button @click="getGoodTypeList()" >刷新</el-button>
    <div>
        <el-tree
        style="max-width: 600px"
        :props="defaultProps"
         :data="goodTypeList"
        show-checkbox
        @node-click="handleNodeClick"
    />
    </div>

   




  <el-dialog v-model="dialogFormVisible" title="添加商品分类" width="500">
    <el-form :model="data">
      <el-form-item label="商品分类名称" :label-width="true">
        <el-input v-model="data.typeName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="父类别Id" :label-width="true">
        <el-input v-model="data.parentId" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="addGoodType">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import type Node from 'element-plus/es/components/tree/src/model/node'
import { ref, reactive, onMounted } from 'vue'
import { ElMessage,ElMessageBox } from 'element-plus'
import { useRouter,useRoute } from 'vue-router'
import axios from 'axios'



const dialogFormVisible = ref(false)

const router=useRouter()
const route=useRoute()
const data=reactive({
    typeName:"",
    parentId:'',
})

onMounted(()=>{
    getGoodTypeList()
})


const handleNodeClick = (data: Tree) => {
  console.log(data)
}

const defaultProps = {
  children: 'children',
  label: 'label',
}
interface Tree {
  name: string
  leaf?: boolean
}
//添加商品类别
const addGoodType=()=>{
dialogFormVisible.value=false;
axios.post("ERP/AddGoodType",data).then(res=>{
    console.log(res)
     if(res.data.code==1)
    {
        ElMessage.success(res.data.message)
        getGoodTypeList();
    }
    else{
        ElMessage.error(res.data.message)
        return;
    } 
})
}

const goodTypeList=ref([])
const getGoodTypeList=()=>{
    axios.get("ERP/GetCasCaders").then(res=>{
        console.log(res)
        goodTypeList.value=res.data
    })
}

    





</script>

<style scoped>


</style>